<template>
	<view>
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar"></view>
		<!-- #endif -->
		<view class="head">
			<image src="../../static/images/arrow_left.png" mode="" @click="goexh"></image>
			<view class="">新增客户</view>
			<view class="f32" @click="visitContacts()">批量导入</view>
		</view>

		<view class="information">
			<view class="name">
				<view class="">* 姓名</view>
				<input type="text" value="" placeholder="请输入供应商名称" v-model="name" />
			</view>
		</view>
		<view class="informationtwo">
			<view class="name">
				<view class="" >* 手机号</view>
				<input type="text" value="" placeholder="请输入手机号" v-model="telephone"  />
				<image src="../../static/client/phone.png" mode="" @click="visitContacts()" ></image>
			</view>
		</view>
		<view class="tui" @click="goAdd">
			<view class="tuiLeft" v-model="rank_id">客户分类</view>
			<text class="jie">{{ user }}</text>
			<view class="tuiRight"><image src="../../static/images/arrow_right.png" mode=""></image></view>
		</view>
		<view class="zhe">
			<view class="zheTop">
				<view class="left">下单折扣</view>
				<view class="right">{{ msg }}</view>
			</view>
			<view class="zheBot">设置折扣，即可在开单时对商品金额默认进行折扣优惠</view>
		</view>
		<view class="tui" style="margin-top: 20rpx;" @click="open">
			<view class="tuiLeft" v-model="address">添加物流地址</view>
			<view class="tuiRight"><image src="../../static/images/arrow_right.png" mode=""></image></view>
		</view>
		<uni-swipe-action v-for="(value, index) in wuliu" :key="index">
			<uni-swipe-action-item :options="options" @click="onClick(index)" >
				<view class="classify">
					<view class="select-item">
						<view class="name f30 c333">{{ value }}</view>
						<view class="arrow"><image src="../../static/images/icon_select.png" mode="aspectFit" @click="addClick(value, index)"></image></view>
					</view>
				</view>
			</uni-swipe-action-item>
		</uni-swipe-action>
		<button type="primary" @click="seaveCommit">保存</button>
		<!-- 添加分类弹窗 -->
		<uni-popup ref="popup" type="center">
			<view class="addContent">
				<view class="box">
					<view class="tit tCenter f36 c333">请输入分类名称</view>
					<view class="input-box"><input type="text" placeholder="请输入分类名称" v-model="ad" /></view>
					<view class="btn f30 tCenter">
						<view class="dropBtn" @click="close">取消</view>
						<view class="submit" @click="tru">确定</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
		  import nativeCommon from '../../js_sdk/WH-VisitContacts/native.common.js';
import jContacts from '@/components/j-contacts/j-contacts.vue';
import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue';
import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue';
export default {
	components: {
		jContacts,
		uniSwipeAction,
		uniSwipeActionItem
	},
	data() {
		return {
			showMask: false,
			mode: 'single',
			hashFirst: false,
			chooseList: [],
			address: '',
			name: '',
			telephone: '',
			rank_id: '',
			ran: {},
			msg: '',
			user: '',
			wuliu: [],
			ad: '',
			options: [
				{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}
			]
		};
	},
	onLoad(e) {

		this.ran=JSON.parse(e.user)
		this.user = this.ran.rank_name;
		this.rank_id=this.ran.rank_id;
		this.name=this.ran.name;
		this.telephone=this.ran.telephone;
		if (this.ran.rank_discount == '100'||this.ran=='') {
			this.msg = '无折扣';
		} else {
			this.msg = this.ran.rank_discount + '折';
		}
	},
	methods: {
		visitContacts() {
		let that=this;
		            nativeCommon.contacts.getContact(function(name, number){
		        that.name=name
		        that.telephone=number
				
		
		            });
		        },
		open() {
			this.$refs.popup.open();
		},
		close() {
			this.$refs.popup.close();
		},
		show(mode) {
			this.showMask = true;
			this.mode = mode;
			this.$refs.jContacts.show();
		},
		contactsConfirm(res) {
			this.chooseList = res;
			this.name=this.chooseList[0].name;
			this.telephone=this.chooseList[0].phone;
			console.log('返回结果：', JSON.stringify(this.chooseList[0].name));
			console.log('返回结果：', JSON.stringify(this.chooseList[0].phone).replace(/\s+/g, ''));
		},
		goAdd() {
			uni.navigateTo({
				url: '../specification/AddtheClassification'
			});
		},
		tru() {
			if (this.ad == '') {
				this.close();
			} else {
				this.wuliu.unshift(this.ad);
				this.ad = '';
				this.wuliu = this.wuliu.filter(item => item);
				// console.log(this.wuliu);
				this.close();
			}
		},
		seaveCommit() {
			// console.log(this.name);
			if(this.name==undefined){
				uni.showToast({
					title:'姓名不能为空',
					icon:'none'
				})
				return
			}
			if(this.telephone==undefined){
				uni.showToast({
					title:'手机号不能为空',
					icon:'none'
				})
				return
			}
			this.$ajax('api/v1.customer/add',{
			address:JSON.stringify(this.wuliu),
			name:this.name,
			rank_id:this.rank_id,
			telephone:this.telephone
		
			    }).then((res)=>{
			 uni.switchTab({
			 url:'../shop/exhibit'
			 })
			    }).catch(res=>{
			     console.log(Error);
			    })
		},
		addClick(value, index) {
			console.log(value, index);
			this.$refs.popup.open();

			this.wuliu[index] = this.ad;
		},
		onClick(e) {
		this.wuliu.splice(e,1)
		},
		goexh(){
			uni.switchTab({
				url:'../shop/exhibit'
			})
		}
	
	}
};
</script>

<style lang="scss">
page {
	background-color: #f7f4f8;
}
.status_bar {
 height: var(--status-bar-height);
 width: 100%;
}
.head {
	height: 88rpx;
	line-height: 88rpx;
	background-color: #249af6;
	color: #ffffff;
	display: flex;
	justify-content: space-between;
	padding: 0 30rpx;
	margin-bottom: 30rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: 500;
	image {
		width: 22rpx;
		height: 39rpx;
		margin-top: 25rpx;
	}
}
.information {
	.name {
		padding: 31rpx 38rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		height: 105rpx;
		background-color: #ffffff;
		border-bottom: 2rpx solid #eeeeee;
		input {
			text-align: right;
		}
	}
	image {
		width: 44rpx;
		height: 44rpx;
	}
}
.informationtwo {
	.name {
		padding: 31rpx 38rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		height: 105rpx;
		background-color: #ffffff;
		border-bottom: 2rpx solid #eeeeee;
		input {
			text-align: right;
			position: relative;
			left: 60rpx;
		}
	}
	image {
		width: 44rpx;
		height: 44rpx;
	}
}
.tui {
	margin-top: 20rpx;
	height: 110rpx;
	background-color: #ffffff;
	padding: 41rpx 38rpx;
	box-sizing: border-box;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
	display: flex;
	border-bottom: 2rpx solid #eeeeee;
	justify-content: space-between;
	image {
		width: 18rpx;
		height: 33rpx;
	}
}
.zhe {
	padding: 30rpx 38rpx;
	box-sizing: border-box;
	background-color: #ffffff;
	font-size: 32rpx;
	.zheTop {
		display: flex;
		justify-content: space-between;
		.right {
			color: red;
			font-size: 32rpx;
		}
	}
	.zheBot {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
		margin-top: 20rpx;
	}
}
// 全部分类
.classify {
	width: 100%;
	background-color: $white-background;
	padding: 30upx 0 0 0;
	.tit {
		border-bottom: 2upx #eee solid;
		padding: 0 30upx 35upx 30upx;
	}
	.select-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		border-bottom: 2upx #eee solid;
		padding: 0 30upx 30upx;
		margin-top: 35upx;
		.arrow {
			image {
				width: 38upx;
				height: 38upx;
			}
		}
	}
}
button {
	width: 100%;
	position: fixed;
	bottom: 0;
}
.jie {
	margin-left: 300rpx;
}
</style>
